# Made by disKret
import sys
from net.sf.l2j.gameserver.model.quest import State
from net.sf.l2j.gameserver.model.quest import QuestState
from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest

#NPC
GAUEN = 7717

#MOBS
SPORE_ZOMBIE = 562
ROTTING_TREE = 558

#QUEST ITEMS
CARNIVORE_SPORE = 5865
HERBIBOROUS_SPORE = 5866

class Quest (JQuest) :

 def __init__(self,id,name,descr):
     JQuest.__init__(self,id,name,descr)
     self.questItemIds = [CARNIVORE_SPORE, HERBIBOROUS_SPORE]

 def onEvent (self,event,st) :
   htmltext = event
   carn=st.getQuestItemsCount(CARNIVORE_SPORE)
   herb=st.getQuestItemsCount(HERBIBOROUS_SPORE)
   if event == "7717-5.htm" :
     if st.getPlayer().getLevel() >= 43 :
       st.set("cond","1")
       st.setState(State.STARTED)
       st.playSound("ItemSound.quest_accept")
     else :
       htmltext = "7717-4.htm"
       st.exitQuest(1)
   elif event in [ "7717-10.htm", "7717-9.htm" ] and (carn>=50 and herb>=50) :
     if event == "7717-9.htm" :
        st.giveItems(57,44000)
     else :
        st.addExpAndSp(36000,2600)
     st.takeItems(CARNIVORE_SPORE,-1)
     st.takeItems(HERBIBOROUS_SPORE,-1)
     st.playSound("ItemSound.quest_finish")
     st.exitQuest(1)
   return htmltext

 def onTalk (self,npc,st):
   htmltext = JQuest.getNoQuestMsg()
   id = st.getState()
   cond = st.getInt("cond")
   carn=st.getQuestItemsCount(CARNIVORE_SPORE)
   herb=st.getQuestItemsCount(HERBIBOROUS_SPORE)
   if cond == 0 :
     htmltext = "7717-0.htm"
   elif cond != 3 :
     htmltext = "7717-6.htm"
   elif cond == 3 or (carn>=50 and herb>=50) :
     htmltext = "7717-7.htm"
   return htmltext

 def onKill (self,npc,player,isPet):
   st = player.getQuestState("356_DigUpTheSeaOfSpores")
   if st :
     if st.getState() != State.STARTED : return
     npcId = npc.getNpcId()
     carn=st.getQuestItemsCount(CARNIVORE_SPORE)
     herb=st.getQuestItemsCount(HERBIBOROUS_SPORE)
     if npcId == SPORE_ZOMBIE and carn < 50 :
       st.giveItems(CARNIVORE_SPORE,1)
       if carn == 49 :
         if herb >= 50 :
           st.playSound("ItemSound.quest_middle")
           st.set("cond","3")
         else :
           st.playSound("ItemSound.quest_middle")
           st.set("cond","2")
       else :
         st.playSound("ItemSound.quest_itemget")	
     elif npcId == ROTTING_TREE and herb < 50 :
       st.giveItems(HERBIBOROUS_SPORE,1)
       if herb == 49 :
         if carn >= 50 :
           st.playSound("ItemSound.quest_middle")
           st.set("cond","3")
         else :
           st.playSound("ItemSound.quest_middle")
           st.set("cond","2")
       else:
         st.playSound("ItemSound.quest_itemget")	
   return

QUEST = Quest(356,"356_DigUpTheSeaOfSpores","Dig Up The Sea Of Spores")
QUEST.addStartNpc(GAUEN)

QUEST.addTalkId(GAUEN)

QUEST.addKillId(562)
QUEST.addKillId(558)